package framework;

import org.elasticsearch.index.query.*;

import java.util.Collection;

/**
 * Created by Administrator on 2017/10/11.
 */
public class QueryBuildersWrapper {

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, String value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, int value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, long value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, float value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, double value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, boolean value) {
        return new TermQueryBuilder(name, value);
    }

    /**
     * 是否相等和这个值
     *
     * @param name  The name of the field
     * @param value The value of the term
     */
    public static TermQueryBuilder termQuery(String name, Object value) {
        return new TermQueryBuilder(name, value);
    }



    /**
     * in的查询
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, String... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * in的查询
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, int... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * in的查询
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, long... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * A filer for a field based on several terms matching on any of them.
     *
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, float... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * A filer for a field based on several terms matching on any of them.
     *
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, double... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * A filer for a field based on several terms matching on any of them.
     *
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, Object... values) {
        return new TermsQueryBuilder(name, values);
    }

    /**
     * A filer for a field based on several terms matching on any of them.
     *
     * @param name   The field name
     * @param values The terms
     */
    public static TermsQueryBuilder termsQuery(String name, Collection<?> values) {
        return new TermsQueryBuilder(name, values);
    }


    /**
     * 模糊查询
     * @param name 属性名
     * @param query *aa*
     * @return
     */
    public static WildcardQueryBuilder wildcardQuery(String name, String query) {
        return new WildcardQueryBuilder(name, query);
    }

    /**
     * 组合查询 must(bool1,bool2)
     * @return
     */
    public static BoolQueryBuilder boolQuery() {
        return new BoolQueryBuilder();
    }


    /**
     * A Query that matches documents within an range of terms.
     * 范围查询
     * @param name The field name
     */
    public static RangeQueryBuilder rangeQuery(String name) {
        return new RangeQueryBuilder(name);
    }

    /**
     * 判断属性名是否存在
     * @param fieldName
     * @return
     */
    public static ExistsQueryBuilder existsQuery(String fieldName){
        return  new ExistsQueryBuilder(fieldName);
    }


    /**
     * 判断属性名是否存在
     * @param fieldName
     * @param value 属性名以什么为前缀
     * @return
     */
    public static PrefixQueryBuilder prefixQuery(String fieldName, String value){
        return  new PrefixQueryBuilder(fieldName,value);
    }

    /**
     * Constructs a query that will match only specific ids within types.
     * 查询主键查询的
     * @param types The mapping/doc type
     */
    public static IdsQueryBuilder idsQuery(String... types) {
        return new IdsQueryBuilder().types(types);
    }

}
